<include file="./head" />
<?php if($_SERVER['HTTP_HOST']==C("SITE_URL")){?>
<include file="./logo" />
<?php }?>
<div class="page-viewport">
  <div class="page-content">
    <div id="navbar" class="nav">
      <ul>
        <li <?php if($cid==0){?> class="current" <?php }?> ><a href="<?php echo U("/Article/index/".$uid); ?>">推荐</a></li>
        <?php foreach($cate as $key=>$v):?>
        <?php if($key==4){?>
        <li id="toggle"> <a class="togglemore" href="javascript:;">更多</a> <a class="togglesingle" href="javascript:;">收起</a> </li>
      </ul>
      <ul class="navmore" <?php if($cid>=5){?> style='display:block;' <?php } ?> >
        <?php } ?>
        <li <?php if($cid==$v['id']){?> class="current" <?php }?>  ><a href="<?php echo list_url($v); ?>"><?php echo $v['name']; ?></a></li>
        <?php endforeach; ?>
      </ul>
    </div>
    <div class="newsList">
      <ul id="newslist">
      </ul>
    </div>
    <div id="PorductListPage" class="comment_page">
      <div id="page"></div>
      </nav>
    </div>
  </div>
</div>
<div class="bottom_line"></div>
<script>
        //导航
        $("#navbar").on("click", "li", function () {
            var toggle = $(this).attr('id');
            if (toggle) {
                $(this).toggleClass("toggle");
                if ($(this).hasClass("toggle")) {
                    $(".navmore").show();
                } else {
                    $(".navmore").hide();
                };
            }
        });
    </script> 
<script type="text/javascript">
            var page_cur = 1; //当前页
            var total_num, page_size, page_total_num;//总记录数,每页条数,总页数
            function getData(page) { //获取当前页数据
                $.ajax({
                    type: 'GET',
                    url: '<?php echo U("/Article/ajax/")."?cid=".$cid; ?>',
                    data: {'page': page - 1},
                    dataType: 'json',
                    success: function(json) {
                        $("#newslist").empty();
                        $(".loading").hide();
                        total_num = json.total_num;//总记录数
                        page_size = json.page_size;//每页数量
                        page_cur = page;//当前页
                        page_total_num = json.page_total_num;//总页数
                        var li = "<li class='nlb'>";
                        var list = json.newslist;
                        $.each(list, function(index, array) { //遍历返回json
                            li +="<a href="+array['url']+">";
							li +="<div class='fr'><h4>"+array['title']+"</h4><p>推荐指数：<span class='star'><label></label><label></label><label></label> <label></label><label></label></span></p>"
							li +="<p>来源：<i>"+array['c_weixin']+"</i> 日期:<i>"+array['time']+"</i></p></div>";
	                        li +="<div class='nlb_pic'><img style='height:auto;' src='"+array['litpic']+"'></div></a>";
							li += "<li>";
                        });
                        $("#newslist").append(li);
                    },
                    beforeSend:function(){
                       $("#newslist").html("文章读取中,请稍等!!!");
                    },
                    complete: function() {
                       getPageBar();//js生成分页，可用程序代替
                    },
                    error: function() {
                        $("#newslist").html("系统超时,请稍等在操作!");
                    }
                });
            }


            $(function() {
                getData(1);//默认第一页
                $("#page a").live('click', function() { //live 向未来的元素添加事件处理器,不可用bind
                    var page = $(this).attr("data-page");//获取当前页
                    getData(page)
                });  
            });

           function getPageBar() { //js生成分页
                if (page_cur > page_total_num)
                    page_cur = page_total_num;//当前页大于最大页数
                if (page_cur < 1)
                    page_cur = 1;//当前页小于1
                page_str = "";//"<span>共" + total_num + "条</span><span>" + page_cur + "/" + page_total_num + "</span>";
                if (page_cur <= 1) {
                    page_str += "<span class='home'>首页</span>";
                } else {
                    page_str += "<span><a href='javascript:void(0)' data-page='" + (page_cur - 1) + "'>上一页</a></span>";
                }
				var chkSelect;
				page_str += '<select name="toPage"  onchange="getData(this.value)">';
				for (var i = 1; i <= page_total_num; i++) {
				if (page_cur == i) chkSelect=' selected="selected"';
				else chkSelect='';
                if(i<10 || i>page_total_num-2){
                   page_str += '<option value="' + i + '"' + chkSelect + '> ' + i + ' / ' + page_total_num + '</option>'; 
                }
				} 
                page_str+="</select>";
				
				
                if (page_cur >= page_total_num || page_total_num==0) { 
                    page_str += "<span class='home'>尾页</span>";
                } else {
                    page_str += "<span><a href='javascript:void(0)' data-page='" + (parseInt(page_cur) + 1) + "'>下一页</a></span>";
                }
                if(total_num>6){
                    $("#page").html(page_str);
                }
                
            }
        </script> 
<?php if($_SERVER['HTTP_HOST']==C("SITE_URL")){?>
<include file="./foot" />
<?php }?>